<!--
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-09-06 00:34:26
 * @LastEditTime: 2019-09-06 00:34:26
 * @LastEditors: your name
 -->
<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>Hello APP</title>
    <link rel="stylesheet" type="text/css" href="../css/vant.css">
    <link rel="stylesheet" type="text/css" href="../css/base.css" />
    <script type="text/javascript" src="../script/jquery.js"></script>
    <script type="text/javascript" src="../script/layer/mobile/layer.js"></script>
    <script type="text/javascript" src="../script/vue.min.js"></script>
    <script type="text/javascript" src="../script/vant.min.js"></script>
    <script type="text/javascript" src="../script/fastclick.js"></script>
    <script type="text/javascript" src="../script/base.js"></script>
    <style type="text/css">
        .van-cell__value {
            text-align: right;
        }
    </style>
</head>

<body>
    <div id="app" v-cloak>
        <div class="init-full">
            <van-nav-bar class="head" title="修改密码" left-arrow @click-left="onClickLeft">
            </van-nav-bar>
            <div class="body-no-bottom">
                <div class="content">
                    <van-field v-model="old_password" type="password" label="旧密码" placeholder="请输入旧密码"></van-field>
                    <van-field v-model="new_password1" type="password" label="新密码" placeholder="请输入新密码"></van-field>
                    <van-field v-model="new_password2" type="password" label="确认新密码" placeholder="请确认新密码"></van-field>
                    <div class="btn-padding">
                        <van-button :disabled="ifConfirm" :loading="ifConfirm" loading-text="数据提交中..." type="primary"
                            block @click="submitConfirm">确认修改</van-button>
                    </div>
                </div>
                <van-loading v-if="showLoading" />
            </div>
        </div>
    </div>
</body>

<script type="text/javascript">
    var vm;
    apiready = function () {
        //$('.init-full').show();
        // var userInfo = FLD.getUserInfo();
        var userInfo = {};
        vm = new Vue({
            el: '#app',
            data: {
                showLoading: false,
                ifConfirm: false,
                old_password: '',
                new_password1: '',
                new_password2: '',
            },
            created: function () {
                var that = this;
            },
            methods: {
                submitConfirm() {
                    var that = this;
                    if (!that.old_password) {
                        layer.open({
                            content: '请填写原密码!',
                            skin: 'msg',
                            time: 2
                        });
                        return false;
                    }
                    if (!that.new_password1) {
                        layer.open({
                            content: '请填写新密码!',
                            skin: 'msg',
                            time: 2
                        });
                        return false;
                    }
                    if (that.new_password1 != that.new_password2) {
                        layer.open({
                            content: '两次输入的密码不一致!',
                            skin: 'msg',
                            time: 2
                        });
                        return false;
                    }
                    var obj = {
                        oldPwd: that.old_password,
                        newPwd: that.new_password1
                    }
                    that.ifConfirm = true;
                    FLD.ajax('updateUserPwd', obj, function (res) {
                        that.ifConfirm = false;
                        if (res.ds[0].status == 200) {
                            window.localStorage.removeItem('printData');
                            window.localStorage.removeItem('userInfo');
                            api.sendEvent({
                                name: 'clearLoginInfo'
                            });
                            layer.open({
                                content: '密码修改成功,请重新登录!',
                                skin: 'msg',
                                time: 2,
                                end: function () {
                                    api.closeToWin({
                                        name: 'root'
                                    });
                                }
                            });
                        } else {
                            layer.open({
                                content: res.ds[0].msg,
                                skin: 'msg',
                                time: 2
                            });
                        }
                    })
                },
                onClickLeft() {
                    api.closeWin();
                }
            }
        })
    }();
</script>

</html>